using System.Collections.Generic;
using System.Linq;
using Castle.DynamicProxy;
using HardMock.Domain;

namespace HardMock.Recording
{
    class MethodCallFactory : IMethodCallFactory
    {
        public MethodCall Create(IInvocation invocation)
        {
            return new MethodCall(invocation.Method, GetArguments(invocation));
        }

        private static IEnumerable<Argument> GetArguments(IInvocation invocation)
        {
            var parameterInfos = invocation.Method.GetParameters();
            for (var i = 0; i < parameterInfos.Count(); i++)
            {
                yield return new Argument(parameterInfos[i].ParameterType, invocation.Arguments[i]);
            }
        }
    }
}